package net.xdclass.service.impl;

import net.xdclass.enums.BizCodeEnum;
import net.xdclass.enums.SendCodeEnum;
import net.xdclass.service.MailService;
import net.xdclass.service.NotifyService;
import net.xdclass.util.CheckUtil;
import net.xdclass.util.CommonUtil;
import net.xdclass.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class NotifyServiceImpl implements NotifyService {


    @Autowired
    MailService mailService;

    /**
     * 标题
     */
    private static  final  String SUBJECT="麟少给的验证码";

    /**
     * 内容
     */
    private static  final  String CONTENT="你的有效时间是一百分钟";

    @Override
    public JsonData sendCode(String to, SendCodeEnum sendCodeEnum) {


        if (CheckUtil.isEmail(to)){

            String ramndomCode = CommonUtil.getRamndomCode(6);
            //邮箱
            mailService.sendMail(to,SUBJECT,String.format(CONTENT,ramndomCode));

            return JsonData.buildSuccess();
        }else if (CheckUtil.isPhone(to)){
            //短信
        }

        return JsonData.buildResult(BizCodeEnum.CODE_TO_ERROR);
    }
}
